import Vuex from 'vuex'
import util from '@/libs/util'

const store = util.store;

export default new Vuex.Store({
    state: {
        access_records: store.get('access_records') || [],
        lock: false
    },
    mutations: {
        add_record(state, postId) {
            if (!postId) throw new Error("postId should not empty ")
            const access_record = {postId: postId, accessAt: new Date()}

            state.access_records.push(access_record);

            store.set('access_records', state.access_records)
        },
        clear_records(state) {
            state.access_records = [];
            store.set("access_records", []);
        },
        set_records(state, records){
            state.access_records = records
            store.set('access_records', state.access_records)
        }
    }
})